﻿using System;
using System.ComponentModel;
using Wizard.UI;

namespace TestWizard
{
    public partial class PasswordPage : InternalWizardPage
    {
        private readonly CreateUserContext _context;

        public PasswordPage(CreateUserContext context)
        {
            _context = context;

            InitializeComponent();
        }

        private void passwordTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void confirmPasswordTextBox_TextChanged(object sender, EventArgs e)
        {
            EnableControls();
        }

        private void EnableControls()
        {
            if (!string.IsNullOrEmpty(passwordTextBox.Text) && passwordTextBox.Text == confirmPasswordTextBox.Text)
                SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
            else
                SetWizardButtons(WizardButtons.Back);
        }

        private void PasswordPage_SetActive(object sender, CancelEventArgs e)
        {
            EnableControls();
        }

        private void PasswordPage_WizardNext(object sender, WizardPageEventArgs e)
        {
            _context.ShowAdvancedPasswordOptions = editAdvancedPasswordOptionsCheckBox.Checked;

            if (_context.ShowAdvancedPasswordOptions)
                e.NewPage = "AdvancedPasswordOptionsPage";
            else
                e.NewPage = "SummaryPage";
        }
    }
}
